<template>
  <div>
    <publish @getValue="getValue" @getImage="getImage" :holder="holder"></publish>
    <button @click="addPic">发布</button>
  </div>
</template>
<style lang="scss">
</style>
<script>
  import headTop from '../header/Header.vue'
  import qs from 'qs'
  import { Toast, Indicator } from 'mint-ui'
  import publish from '../common/publish.vue'

  export default {
    name: 'ToRent',
    components: {
      publish
    },
    data () {
      return {
        houseDetail: '',
        imagesLrz: [],
        showLoading: false,
        holder: '例如出租17幢2单元1003室101m²(字数不超过200)'
      }
    },
    created () {
    },
    methods: {
      getValue (value) {
        this.houseDetail = value
      },
      getImage (image) {
        this.imagesLrz = image
      },
      addPic () {
        setTimeout(function () {
          Indicator.close()
        }, 15000)
        if (!this.houseDetail.trim().length || !this.houseDetail || !this.imagesLrz.length) {
          Toast({
            message: '请填写完整信息',
            position: 'middle',
            duration: 2000
          })
          return
        }
        Indicator.open({
          text: '发布中...',
          spinnerType: 'fading-circle'
        })
        const url = "https://ynwx.zgwyzxw.cn/index.php/home/renthouse/add"
        const data = {
          title: 'yn',
          content: this.houseDetail,
          img: this.imagesLrz,
          areas_id: 204,
          openid: 'oHVoI1YFA6zvN1ymtrO4WrrRrmzA'
        }
        this.$http.post(url, qs.stringify(data), {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).then(res => {
          if (res.data.code === 200) {
            Indicator.close()
            Toast({
              message: '发布成功',
              position: 'middle',
              duration: 1500
            })
            this.$router.back()
          }
        })
      }
    }
  }
</script>
